package com.inspur.web.controller.system;

import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.system.domain.PmBus;
import com.inspur.system.service.IPmBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 模块管理
 */
@RestController
@RequestMapping("/system/bus")
public class PmBusController extends BaseController {

    @Autowired
    private IPmBusService iPmBusService;

    /**
     * 添加
     * @param pmBus
     * @return
     */
    @PostMapping
    @PreAuthorize("@ss.hasPermi('system:bus:add')")
    public AjaxResult insertPmBus(@RequestBody PmBus pmBus){
        System.out.println(pmBus);
        int i = iPmBusService.insertPmBus(pmBus);
        return AjaxResult.success(i);
    }

    /**
     * 分页查询
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('system:bus:query')")
    public AjaxResult list(
            @RequestParam(required = false,defaultValue = "1") Integer pageNumber,
            @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        PmBus pmBus = new PmBus();
        Map<String, Object> map = iPmBusService.selectPmBusList(pageNumber, pageSize, pmBus);
        return  AjaxResult.success(map);
    }

    /**
     * 删除
     * @param busNo
     * @return
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('system:bus:delete')")
    public AjaxResult remove(@PathVariable(value = "id") String busNo){
        int i= iPmBusService.deletePmBus(busNo);

        return toAjax(i);
    }

    /**
     * 修改
     * @param pmBus
     * @return
     */
    @PutMapping
    @PreAuthorize("@ss.hasPermi('system:bus:update')")
    public AjaxResult updatePmBus(@RequestBody PmBus pmBus){
        return AjaxResult.success(iPmBusService.updatePmBus(pmBus));
    }

}

